package com.polaris.live.adapter

import android.view.View
import com.blankj.utilcode.util.StringUtils
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.polaris.live.R.drawable
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.cacha.CacheUtil
import com.polaris.live.common.ext.autoDp
import com.polaris.live.common.util.DateUtils
import com.polaris.live.databinding.AdapterRoomSkinBinding
import com.polaris.live.dialog.RoomSkinDialog
import com.polaris.live.resp.back_resp.UserRoomThemeVo
import com.polaris.live.translation.R
import com.polaris.live.utils.CommonUtils.toBoolean
import com.polaris.live.utils.image.loadImage
import com.polaris.live.utils.image.transformRounded

/**
 * RoomSkinAdapter
 *
 * @author Created by 半仙 on 2024/12/23/023 16:05
 */
class RoomSkinAdapter : BaseBindingAdapter<AdapterRoomSkinBinding, UserRoomThemeVo>() {

    override fun convert(holder: VBViewHolder<AdapterRoomSkinBinding>, item: UserRoomThemeVo) {
        holder.vb.apply {
            tvName.text = if (item.name == RoomSkinDialog.DEFAULT_NAME) {
                StringUtils.getString(R.string.default_string)
            } else {
                "VIP${item.name}"
            }

            if (item.useStatus.toBoolean()) {
                consBack.setBackgroundResource(drawable.back_pack_select_back)
                tvUsering.visibility = View.VISIBLE
            } else {
                consBack.setBackgroundResource(drawable.r8_back_ffffff)
                tvUsering.visibility = View.GONE
            }

            if (item.url.isNullOrEmpty()) {
                Glide.with(context).load(drawable.default_party_bg).transformRounded(4.autoDp).into(ivCover)
            } else {
                Glide.with(context).loadImage(item.url).transform(RoundedCorners(4.autoDp)).into(ivCover)
            }

            if (item.activated) {
                val expiredTime = item.expireTime
                if (expiredTime == null) {
                    tvTime.text = StringUtils.getString(R.string.permanent)
                } else {
                    tvTime.text = DateUtils.formatTime(expiredTime.toLong() - CacheUtil.getServerTime())
                }
                consMask.visibility = View.GONE
            } else {
                consMask.visibility = View.VISIBLE
                tvTime.text = "0"
            }
        }
    }
}